#include <stdlib.h>
#include <stdio.h>

/*
  Name: Manuel
  Copyright: 
  Author: UCP
  Date: 30/01/09 08:14
  Description: Dynamicly allocated two-dimensional array
*/


int main(){ 
    
    int nrows,ncolumns,i,j;
    nrows=3;
    ncolumns=3;
    
    typedef struct {    
	int **array;
    } matrice;
    matrice mat;
    
	mat.array = malloc(nrows * sizeof(int *));
	if(mat.array == NULL)
		{
		fprintf(stderr, "out of memory\n");
		return 0;
		}
	for(i = 0; i < nrows; i++)
		{
		mat.array[i] = malloc(ncolumns * sizeof(int));
		if(mat.array[i] == NULL)
			{
			fprintf(stderr, "out of memory\n");
		return 0;
			}
	}
	
	 for(i = 0; i < nrows; i++)
		{
		for(j = 0; j < ncolumns; j++)
			mat.array[i][j] = 0;
		}
		
		for(i = 0; i < nrows; i++)
		{
		for(j = 0; j < ncolumns; j++)
			printf("%d",mat.array[i][j]);
        printf("\n");
        }

	
	system("pause");
	return 0;
}
